home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / tcp / amitcp / amitcp-api-22.lha / AmiTCP-2.2 / src / netlib / gettimeofday.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-18  |  3.3 KB  |  115 lines

  1. RCS_ID_C="$Id: gettimeofday.c,v 1.1 1993/10/18 06:23:47 jraja Exp $"
  2. /*
  3.  * gettimeofday.c --- get time of the day
  4.  *
  5.  * Author: jraja <Jarno.Rajahalme@hut.fi>
  6.  *
  7.  * Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  8.  *                  Helsinki University of Technology, Finland.
  9.  *                  All rights reserved.
  10.  *
  11.  * Created      : Wed Sep 01 22:45:12 1993 jraja
  12.  * Last modified: Wed Sep 01 22:45:12 1993 jraja
  13.  *
  14.  * $Log: gettimeofday.c,v $
  15.  * Revision 1.1  1993/10/18  06:23:47  jraja
  16.  * Initial revision
  17.  *
  18.  */
  19.  
  20. #include <sys/param.h>
  21. #include <sys/time.h>
  22.  
  23. /****** net.lib/gettimeofday *********************************************
  24. *
  25. *   NAME   
  26. *       gettimeofday - get date and time 
  27. *
  28. *   SYNOPSIS
  29. *       #include <sys/time.h>
  30. *
  31. *       error = gettimeofday(tp, tzp)
  32. *
  33. *       int gettimeofday(struct timeval *, struct timezone *)
  34. *
  35. *   FUNCTION
  36. *       The system's notion of the current Greenwich time and the
  37. *       current time zone is obtained with the gettimeofday() call.
  38. *       The time is expressed in seconds and microseconds since
  39. *       midnight (0 hour), January 1, 1970.  The resolution of the
  40. *       system clock is hardware dependent. If tzp is zero, the time
  41. *       zone information will not be returned. Also, if your system
  42. *       software is unable to provide time zone information, the
  43. *       structure pointed by tzp will be filled with zeroes.
  44. *  
  45. *   PORTABILITY
  46. *       UNIX
  47. *
  48. *   INPUTS
  49. *       The structures pointed to by tp and tzp are defined in
  50. *       <sys/time.h> as:
  51. *  
  52. *            struct timeval {
  53. *                 long tv_sec;      \* seconds since Jan. 1, 1970 *\
  54. *                 long tv_usec;     \* and microseconds *\
  55. *            };
  56. *  
  57. *            struct timezone {
  58. *                 int  tz_minuteswest;   \* of Greenwich *\
  59. *                 int  tz_dsttime;  \* type of dst correction to apply *\
  60. *            };
  61. *  
  62. *       The timezone structure indicates the local time zone (meas-
  63. *       ured in minutes of time westward from Greenwich), and a flag
  64. *       that, if nonzero, indicates that Daylight Saving time
  65. *       applies locally during the appropriate part of the year.
  66. *
  67. *   RESULT
  68. *       Returns 0 when successful and -1 with specific error code in 
  69. *       errno in case of an error. No error codes are specified,
  70. *       however.
  71. *       
  72. *   NOTES
  73. *       gettimeofday() uses GetSysTime() function of the timer.device,
  74. *       which is new to V36 of the device.
  75. *
  76. *       Time zone information is available only if your system has
  77. *       locale.library, which is included in all Amiga systems from
  78. *       2.1 and up.
  79. *
  80. *       Global variable TimerBase _must_ be initialized before
  81. *       gettimeofday() is called. This is normally done automatically
  82. *       by the autoinit module (timerinit.c) included in the net.lib.
  83. *
  84. *   BUGS
  85. *       The time zones are currently not supported.
  86. *
  87. *   SEE ALSO
  88. *       timer.device/GetSysTime()
  89. *****************************************************************************
  90. *
  91. */
  92.  
  93. /*
  94.  * See timerinit.c for comments on these
  95.  */
  96. extern struct timezone __time_zone;
  97. extern long __local_to_GMT;
  98.  
  99. int 
  100. gettimeofday(struct timeval *tp, struct timezone *tzp)
  101. {
  102.   if (tp) {
  103.     GetSysTime(tp);
  104.     tp->tv_sec += __local_to_GMT;
  105.   }
  106.   if (tzp) {
  107.     /*
  108.      * __time_zone is set up in the timerinit.c
  109.      */
  110.     *tzp = __time_zone;
  111.   }
  112.  
  113.   return 0;
  114. }
  115.